package com.zhongke.cotrun.mapper;

import com.zhongke.cotrun.model.pojo.Integral;
import com.zhongke.cotrun.model.pojo.IntegralVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface IntegralMapper {
    /**
     * 新建积分类型
     *
     * @param integral
     * @return
     */

    @Insert("INSERT INTO `integral` (`integral_name`, `explain`, `port`, `create_time`,`update_time`,`create_id`,`state`,`hop_routing`) VALUES (#{integralName}, #{explain}, #{port}, NOW(),NOW(), #{createId},0,#{hopRouting})")
    public boolean insertIntegral(Integral integral);

    /**
     * 修改
     *
     * @param integral
     * @return
     */
    public Boolean updateIntegral(Integral integral);

    /**
     * 查看具体的
     *
     * @param integralId
     * @return
     */
    @Select("SELECT integral_name,`explain`,`port`  FROM integral WHERE integral_id=#{integralId}")
    public Integral selectIntegralById(Integer integralId);

    /**
     * 按条件查看所有的
     *
     * @return
     */
//    @Select("SELECT integral_id,integral_name,`explain`,create_id,update_time FROM integral")
    public List<IntegralVo> selectAllIntegral(Integral integral);

    /**
     * 根据接口查询积分类别
     *
     * @param port
     * @return
     */

    @Select("SELECT integral_id,integral_name,`explain`,`port`  FROM integral WHERE port=#{port} and `state`=0")
    public Integral selectIntegralByPort(String port);

    /**
     * 修改积分类型状态
     *
     * @param state
     * @return
     */
    @Update("UPDATE `integral` SET `state`=#{state} WHERE (`integral_id`=#{integralId})")
    public Boolean updateInteStatue(@Param("state") Integer state, @Param("integralId") Integer integralId);

    /**
     * 后台积分规则搜索
     * @param integral
     * @return
     */
    public List<IntegralVo> selectIntegralAndRecord(Integral integral);

}
